package com.itheima_17;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class ArrayListToFileDemo {
    public static void main(String[] args) throws IOException {

        ArrayList<Student> arrayList = new ArrayList<Student>();

        Student s1 = new Student("001","张曼玉","60","香港");
        Student s2 = new Student("002","孙俪","50","上海");
        Student s3 = new Student("003","邓超","50","北京");
        Student s4 = new Student("004","陈赫","44","西安");
        Student s5 = new Student("005","迪丽热巴","30","山西");

        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);
        arrayList.add(s4);
        arrayList.add(s5);

        BufferedWriter bw = new BufferedWriter(new FileWriter("/Users/oscar/Desktop/HQWork/学习资料/code/mySimpleDateFormat/student.txt"));

        for (Student s : arrayList) {
//           bw.write(s.getId()+","+s.getName()+","+s.getAge()+","+s.getAddress());
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(s.getId()).append(",").append(s.getName()).append(",").append(s.getAge()).append(",").append(s.getAddress());
            bw.write(stringBuilder.toString());
            bw.newLine();
            bw.flush();
        }

        bw.close();

    }
}
